package easy.实现strStr;

/**
 * 实现strStr
 *
 * @author CodeX
 * @since 2021-09-28 09:52:03
 */
@SuppressWarnings("all")
public class Strstr {

    public static int strStr(String haystack, String needle) {
        int i1 = haystack.length();
        int i2 = needle.length();
        for (int i = 0; i + i2 <= i1; i++) {
            boolean flag = true;
            for (int j = 0; j < i2; j++) {
                if (haystack.charAt(i + j) != needle.charAt(j)) {
                    flag = false;
                    break;
                }
            }
            if (flag){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        String haystack = "hello", needle = "ll";
        System.out.println(strStr(haystack, needle));
    }

}
